<?php
class Settings extends Controller {
    function Settings()
    {
        parent::Controller();
        $this->load->helper(array('form'));
        $this->load->library('form_validation'); 
        $this->load->model('Model_settings');    
    }
    
    function index()
    {
        $test = $this->Model_settings->get_settings(1);
        
        if(empty($test)){       
            $test["email_alert"] = "";
            $test["email_address"] = "" ;
            $test["sms_alert"] = "";
            $test["phone_number"] = ""; 
            $test["advertising"] = "";
        }
        $test["classonsetttings"] = 1;
        //echo "<pre>";print_r($test);echo "</pre>";
        $this->load->view(TEMPLATE_NAME.'/front/profile/settings' , $test);   
    }
    
    function submit()
    {        
        $data = $this->Model_settings->get_settings(1);
        if($data){                
            $form = array(
                'user_tiab_id'     => $this->input->post('user_tiab_id'),
                'email_alert'      => $this->input->post('email_alert'),
                'email_address'    => $this->input->post('email_address'),
                'sms_alert'        => $this->input->post('sms_alert'),
                'phone_number'     => $this->input->post('phone_number'),
                'advertising'      => $this->input->post('advertising'),
                
            );
            $this->Model_settings->update_settings($data["id"],$form);                
        }else{               
            $user_tiab_id   = $this->input->post('user_tiab_id');
            $email_alert    = $this->input->post('email_alert');
            $email_address  = $this->input->post('email_address');
            $sms_alert      = $this->input->post('sms_alert');
            $phone_number   = $this->input->post('phone_number');
            $advertising    = $this->input->post('advertising');            
            
            $this->Model_settings->insert_settings($user_tiab_id, $email_alert, $email_address, $sms_alert, $phone_number, $advertising);                      
        }
        
        $test = $this->Model_settings->get_settings(1);
        $test["classonsetttings"] = 1;
                           
        //echo "<pre>";print_r($test);echo "</pre>";
        $this->load->view(TEMPLATE_NAME.'/front/profile/settings', $test);
    }
}
?>
